package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.net.*;
    import flash.text.*;
    import com.greensock.*;

    public class ProjectIconImage extends Sprite
    {
        var loader:Loader;
        var imagePath:String;
        var fadeSpeed:Number;
        public var dbId:int;
        public var btnOver:Sprite;
        var image:Bitmap;
        var imageBorder:String;
        public var idNum:Number;
        public var btn:Sprite;
        var frame:Frame;
        var myRoot:MovieClip;
        public var shortText:ShortText;
        var myText:String;

        public function ProjectIconImage(param1:MovieClip, param2:Number, param3:String, param4:Number, param5:int, param6:String, param7:String) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            myText = param3;
            idNum = param4;
            dbId = param5;
            imagePath = param6;
            imageBorder = param7;
            buildImage();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer);
            doResize();
            return;
        }

        public function rollOverEvent() : void
        {
            TweenMax.to(btnOver, fadeSpeed, {alpha:0.5, overwrite:true});
            return;
        }

        function doResize() : void
        {
            var _loc_1:* = Math.round(3 * myRoot.unitW + 3 * myRoot.gutterW);
            btnOver.width = Math.round(3 * myRoot.unitW + 3 * myRoot.gutterW);
            btn.width = _loc_1;
            var _loc_1:* = Math.round(2 * myRoot.unitH + 2 * myRoot.gutterH);
            btnOver.height = Math.round(2 * myRoot.unitH + 2 * myRoot.gutterH);
            btn.height = _loc_1;
            if (image != null)
            {
                image.width = Math.round(3 * myRoot.unitW + 2 * myRoot.gutterW);
                image.height = Math.round(2 * myRoot.unitH + myRoot.gutterH);
            }
            if (frame != null)
            {
                frame.resizeFrame(image.width, image.height);
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        public function rollOutEvent() : void
        {
            TweenMax.to(btnOver, fadeSpeed * 3, {alpha:0, overwrite:true});
            return;
        }

        function buildImage() : void
        {
            var _loc_1:* = undefined;
            _loc_1 = new TextFormat();
            _loc_1.font = new HelveticaLightEmbed().fontName;
            _loc_1.size = 14;
            _loc_1.letterSpacing = 0;
            _loc_1.leftMargin = 0;
            _loc_1.rightMargin = 0;
            _loc_1.color = myRoot.coldColor;
            btn = new Sprite();
            btn.useHandCursor = true;
            btn.mouseEnabled = true;
            btn.buttonMode = true;
            btn.mouseChildren = false;
            btn.graphics.beginFill(16777215, 100);
            btn.graphics.drawRect(0, 0, 1, 1);
            btn.graphics.endFill();
            btnOver = new Sprite();
            btnOver.useHandCursor = false;
            btnOver.mouseEnabled = false;
            btnOver.buttonMode = false;
            btnOver.graphics.beginFill(16777215, 100);
            btnOver.graphics.drawRect(0, 0, 1, 1);
            btnOver.graphics.endFill();
            btnOver.alpha = 0;
            addChild(btn);
            addChild(btnOver);
            loader = new Loader();
            loader.load(new URLRequest(myRoot.path + imagePath));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
            return;
        }

        function onLoadComplete(event:Event) : void
        {
            var imageBMP:BitmapData;
            var newHeight:int;
            var newWidth:int;
            var imageBMPData:BitmapData;
            var event:* = event;
            if (loader.content.width != 243 && loader.content.height != 243)
            {
                imageBMP = new BitmapData(loader.width, loader.height);
                imageBMP.draw(loader, new Matrix());
                if (loader.height <= 243)
                {
                    newHeight = loader.height;
                }
                else
                {
                    newHeight;
                }
                newWidth = newHeight;
                imageBMPData = new BitmapData(newWidth, newHeight);
                imageBMPData.copyPixels(imageBMP, new Rectangle((loader.width - newWidth) / 2, (loader.height - newHeight) / 2, newWidth, newHeight), new Point(0, 0));
                image = new Bitmap(imageBMPData);
            }
            else
            {
                image = Bitmap(loader.content);
            }
            doResize();
            image.alpha = 0;
            addChild(image);
            if (imageBorder == "1")
            {
                frame = new Frame();
                frame.alpha = 0;
                addChild(frame);
                frame.resizeFrame(image.width, image.height);
                TweenMax.to(frame, fadeSpeed, {alpha:1, overwrite:true});
            }
            addChild(btnOver);
            TweenMax.to(image, fadeSpeed, {alpha:1, overwrite:true, onComplete:function ()
            {
                image.smoothing = true;
                return;
            }
            });
            return;
        }

        public function fadeInShell() : void
        {
            TweenMax.to(this, fadeSpeed, {alpha:1, overwrite:true});
            return;
        }

    }
}
